import router from './router'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
import { Notification } from 'element-ui'
import { getToken } from '@/router/cookie'


router.beforeEach((to, from, next) => {
  NProgress.start()
  
  if(getToken()){
    if(to.path === '/'){
      next({ path:'/home' })
      NProgress.done()
    }else{
      next()
    }
  }else{
    
    if( to.path === '/'){

      next( )
    }else{
      Notification.error({
        title:'不好意思',
        message:'您还未登录,请登录后重试',
        duration:2000
      })
      next({ path:'/' })
      NProgress.done()
    }
  }

  
})

router.afterEach((to,from) => {

  NProgress.done() 
})
